<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" session="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="renderer" content="webkit">
    <META HTTP-EQUIV="Pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache">
    <META HTTP-EQUIV="Expires" CONTENT="0">
    <title>报修管理</title>

    <link href="${pageContext.request.contextPath}/static/css/common.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/css/bootstrap.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/font-awesome-4.3.0/css/font-awesome.min.css"
          rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/css/select2.min.css"
          rel="stylesheet">
    <!-- jqgrid-->
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/custom.ui.jqgrid.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/layer/skin/layer.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/static/plugins/jqGrid/css/style.css" rel="stylesheet">

    <script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/jquery.form.js"></script>
    <script src="${pageContext.request.contextPath}/static/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/bootstrap-3.3.5/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/i18n/grid.locale-cn.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/jqGrid/js/minified/jquery.jqGrid.min.js"></script>
    <script src="${pageContext.request.contextPath}/static/plugins/layer/layer.js" type="text/javascript"></script>
	<script src="${pageContext.request.contextPath}/static/js/global.js"></script>
	<script src="${pageContext.request.contextPath}/static/plugins/select2-4.0.0/dist/js/select2.min.js"></script>
	<script type="text/javascript"
            src="${pageContext.request.contextPath}/static/plugins/My97DatePicker/WdatePicker.js"></script>
    <style type="text/css">
        .main h5 a {
            position: absolute;
            right: 20px;
            font-size: 14px;
            bottom: 0px;
            display: inline-block;
            padding: 5px;
        }

        .table_list tbody tr {
            height: 35px;
            text-align: center;
        }
        .butt{
        	width: 100px;
		}
		.left ul li{

			*line-height:40px;
			*+background:#484848;
			*padding-left:20px;
		}

		.left ul li a, .left ul li a:hover{
			*color:#fff;
		}
		.list-tab li{
			*+padding:0px 10px 10px;
		}
		.wrapper{
			*margin-left:270px;
		}
		.btn{
			*width:60px;
		}
		.lt{
			float:left;
		}
		.ui-pg-button{
			*background:#ccc;
		}
		.col-md-3{
			*width:100px;
		}
		.form-group{
			*overflow: hidden;
		}
		.selectlabe1{*+width:70px !important;}
		.form-control{*+height:28px;}
		.btn{*+;line-height:14px;}
    </style>
</head>
<body view="menu-item-4142">
<jsp:include page="../../top.jsp"></jsp:include>
<div class="right">
 	<div class="wrapper">
        <div class="panel panel-default">
            <div class="panel-heading">
                <span><strong>查询条件</strong></span>

                <div class="ibox-tools">
                    <a class="collapse-link"> <i class="fa fa-chevron-down"></i></a>
                    <a class="collapse-link  d-n"> <i class="fa fa-chevron-up"></i></a>
                </div>
            </div>
            <div class="panel-body">
                <form class="form-horizontal">
			        <c:if test="${userRole == 1 || userRole == 2 || userRole == 21}">
		                <div class="form-group">
		               		<label class="selectlabe1 col-md-1 form-lable lt">公司名称：</label>
		                    <div class="selectdivs col-md-3 lt">
		                        <select name="agtCode" id="agtCode" class="form-control col-md-1"></select>
		                    </div>

		                    <label class="selectlabe2 col-md-1 lt form-lable" style="width: 90px;">小区名称：</label>
		                    <div class="selectdivs col-md-3 lt" >
		                        <select name="communityId" id="communityId" class="form-control col-md-1"></select>
		                    </div>
		                    <label class="selectlabe2 col-md-1 form-lable lt" >所属区域：</label>
				            <div id="region" class="col-md-3 lt" style="width: 16%;padding-left: 0px;">
				                <script type="text/javascript">
				                    loadCity();
				                </script>
				            </div>
		         		</div>

         			</c:if>
			        <c:if test="${userRole == 3 || userRole == 4}">
			          	<div class="form-group">
			          		<label class="selectlabe1 col-md-1 lt form-lable" style="width: 90px;">小区名称：</label>
		                    <div class="col-md-3 lt" >
		                        <select name="communityId" id="communityId" class="form-control col-md-1"></select>
		                    </div>
		                    <label class="selectlabe2 col-md-1 lt form-lable" >所属区域：</label>
				            <div id="region" class="col-md-3 lt" style="width: 16%;padding-left: 0px;">
				                <script type="text/javascript">
				                    loadCity();
				                </script>
				            </div>
				        </div>
			         </c:if>
			         <c:if test="${userRole == 5 || userRole == 6}">
			         	<div class="form-group">
				         	<label class="selectlabe1 lt col-md-1 form-lable">住户姓名：</label>
	                        <div class="col-md-3 lt" >
	                            <input id="userName" name="userName" type="text" class="form-control"/>
	                        </div>
				         	<label class="selectlabe2 lt col-md-1 form-lable">住户手机：</label>
	                        <div class="col-md-3 lt" >
	                            <input id="userTel" name="userTel" type="text" class="form-control"/>
	                        </div>
			         	</div>
				      </c:if>
	                      <div class="form-group">
	                        <label class="selectlabe1 lt col-md-1 form-lable">回复状态：</label>
				     		<c:if test="${userRole == 1 || userRole == 2  || userRole == 21}">
	                        	<div class="selectdivs col-md-3 lt">
		                            <select name="replytype" id="replytype" class="form-control col-md-1 lt">
		                                <option value="">请选择回复状态</option>
		                                <option value="0">待回复</option>
		                                <option value="1">已回复</option>
		                            </select>
		                           </div>
	                		</c:if>
	                		<c:if test="${userRole != 1 && userRole != 2 && userRole != 21}">
	                			<div class="col-md-3 lt">
	                				<select name="replytype" id="replytype" class="form-control col-md-1 lt">
		                                <option value="">请选择回复状态</option>
		                                <option value="0">待回复</option>
		                                <option value="1">已回复</option>
		                            </select>
		                         </div>
	                		</c:if>

	                        <label class="selectlabe2 col-md-1 form-lable lt">维修状态：</label>
	                        <c:if test="${userRole != 5 && userRole != 6}">
		                        <div class="selectdivs col-md-3 lt">
		                            <select name="status" id="status" class="form-control col-md-1 lt">
		                                <option value="">请选择维修状态</option>
		                                <option value="2">住户撤销</option>
		                                <option value="1">等待处理</option>
		                                <option value="3">未接单</option>
		                                <option value="5">已接单</option>
		                                <option value="4">完成维修</option>
		                            </select>
		                        </div>
	                        </c:if>
	                        <c:if test="${userRole == 5 || userRole == 6}">
		                        <div class="col-md-3 lt">
		                            <select name="status" id="status" class="form-control col-md-1 lt">
		                                <option value="">请选择维修状态</option>
		                                <option value="2">住户撤销</option>
		                                <option value="1">等待处理</option>
		                                <option value="3">未接单</option>
		                                <option value="5">已接单</option>
		                                <option value="4">完成维修</option>
		                            </select>
		                        </div>
	                        </c:if>
	                       <div class="col-md-1 form-action lt">
                            <button class="btn btn-success form-control" id="query">查询</button>
	                        </div>
	                        <div class="col-md-1 form-action lt">
	                            <button class="btn btn-success form-control" id="resetForm">清空</button>
	                        </div>
	                    </div>
                </form>
            </div>
        </div>
	    <div class="jqGrid_wrapper">
	        <div id="jqGrid_operation" class="jg-grid">
	            <h1></h1>
	            <div class="jqGrid_operation" id="action"></div>
	        </div>
	        <table id="jqGrid"></table>
	        <div id="jqGrid_paper"></div>
	    </div>
	</div>
</div>
<script>
	var ifreply = false;
    $(document).ready(
            function () {
            	$.ajax({
                    type: "POST",
                    async: false,
                    url: '/admin/auth_buttons.action',
                    data: "url=" + window.location.pathname,
                    success: function (data) {
                        data = eval("(" + data + ")");
                        for (var i in data) {
                            var action = data[i].mName;
                            switch (action) {
                                case "报修删除":
                                    $("#action").append("<a id=\"del\"><i class=\"glyphicon glyphicon-trash\"></i>删除</a>");
                                    $("#del").click(function () {
                                        var sels = jQuery("#jqGrid").jqGrid('getGridParam', 'selarrrow');
                                        if (sels == "") {
                                            layer.alert("请选择要删除的维修记录", {
                                                icon: 6,
                                                closeBtn: false
                                            });
                                        } else {
                                            layer.confirm('确认删除所选择的维修记录', function (index) {
                                                $.post("${pageContext.request.contextPath}/admin/fix_delete.action", {
                                                    "ids": sels.toString()
                                                }, function (result) {
                                                    result = eval("(" + result + ")");
                                                    layer.alert(result.msg);
                                                    refreshGrid();
                                                });
                                                layer.close(index);
                                            });
                                        }
                                    });
                                    break;
                                case "报修回复":
                                	 ifreply = true;
                                	 break;
                            }
                        }
                    }
                });
                $.jgrid.defaults.styleUI = "Bootstrap";
                if('${userRole}'==1 || '${userRole}'==2){
	                $("#jqGrid").jqGrid({
	                      url: "${pageContext.request.contextPath}/admin/fix_page.action",
	                      mtype: 'POST',
	                      datatype: "json",
	                       height: 362,
	                      autowidth: true,
	                      shrinkToFit: true,
	                      rowNum: 10,
	                      rowList: [10, 20, 30],
	                      colNames: ['序号','申请时间','所属区域', '公司', '小区名称', '楼栋单元',
	                          '房间号', '姓名', '手机号','维修人员姓名','维修人员手机','完成时间','回复住户','维修状态'],
	                      colModel: [{
	                          name: "SID",
	                          index: "SID",
	                          key: true,
	                          hidden: true
	                      }, {
	                          name: 'CTIME',
	                          index: 'CTIME',
	                          width: 90
	                      }, {
	                          name: 'CITYCODE',
	                          index: 'CITYCODE',
	                          width: 90
	                      }, {
	                          name: 'AGTNAME',
	                          index: 'AGTNAME',
	                          width: 90
	                      }, {
	                          name: 'COMMUNITYNAME',
	                          index: 'COMMUNITYNAME',
	                          width: 80
	                      },{
	                          name: 'CBNAME',
	                          index: 'CBNAME',
	                          width: 80
	                      }, {
	                          name: "ROOM",
	                          index: "ROOM",
	                          width: 80
	                      },{
	                          name: "AUNAME",
	                          index: "AUNAME",
	                          width: 80
	                      }, {
	                          name: "APPLYTEL",
	                          index: "APPLYTEL",
	                          width: 90
	                      },{
	                          name: "FIXNAME",
	                          index: "FIXNAME",
	                          width: 80
	                      }, {
	                          name: "FIXTEL",
	                          index: "FIXTEL",
	                          width: 90
	                      }, {
	                          name: "FINISHTIME",
	                          index: "FINISHTIME",
	                          width: 90
	                      }, {
	                          name: "STATUS",
	                          index: "STATUS",
	                          width: 80,
	                          formatter: function (cellvalue, options, rawObject) {
		                          	if(cellvalue=='-1' || !cellvalue){
		                              	return '';
		                              }if (cellvalue == 1){
		                              	return "待回复";
		                              }if (cellvalue == 2 && !rawObject.FIXNAME){
		                            	  return "<font style='color: #908e8e;'>待回复</font>";
		                              }else{
		                              	return "<a onclick='replyDetail("+rawObject.SID+")'>已回复</a>";
		                              }
		                          }


	                      }, {
	                          name: "STATUS",
	                          index: "STATUS",
	                          width: 80,
	                          formatter: function (cellvalue, options, rawObject) {
	                          	  if (cellvalue == 1){
										return "<font style='color: red;'>等待处理</font>";
	                              }else if (cellvalue == 2 ){
	                              	return "<font style='color: #908e8e;'>住户撤销</font>";
	                              }else if (cellvalue == 3 ){
	                              	return "<font style='color: red;'>未接单</font>";
	                              }else if (cellvalue == 4 ){
	                              	return "<font style='color: black;'>完成维修</font>";
	                              }else if (cellvalue == 5 ){
	                              	return "<font style='color: black;'>已接单</font>";
	                              }else{
	                            	  return '';
		                          }
	                          }
	                      }],
	                      sortname: 't.sid',
	                      sortorder:'desc',
	                      rownumbers: true,
	                      jsonReader: {
	                          root: 'rows',
	                          page: "page",
	                          total: 'total',
	                          records: "records",
	                          repeatitems: false
	                      },
	                      pager: "#jqGrid_paper",
	                      viewrecords: true,
	                      multiselect: true,
	                      hidegrid: false,
	                      loadComplete: function(){
	                    		var re_records = Number($("#jqGrid").getGridParam('records'));
	                    		var page = Number($("#jqGrid").getGridParam('page'));
	                    		var rows=Number($("#jqGrid").getGridParam('rowNum'));
	                    		var num = re_records-(page-1)*rows;
	                    		if(num < rows)
	                    		{
	                    			for(var i=num;i<rows;i++){
	                    				$("#jqGrid").jqGrid("addRowData",(i+1),
	                            				{ "SID":"","STATUS":"-1"}
	                    				,"");
	                    			}
	                    			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
	                    		}
	                    	}
	                  });
                }else if('${userRole}'==3 || '${userRole}'==4){//合作方客户
                	$("#jqGrid").jqGrid({
	                      url: "${pageContext.request.contextPath}/admin/fix_page.action",
	                      mtype: 'POST',
	                      datatype: "json",
	                      height: 362,
	                      autowidth: true,
	                      shrinkToFit: true,
	                      rowNum: 10,
	                      rowList: [10, 20, 30],
	                      colNames: ['序号','申请时间','所属区域', '小区名称', '楼栋单元',
	                          '房间号', '姓名', '手机号','维修人员姓名','维修人员手机','完成时间','回复住户','维修状态'],
	                      colModel: [{
	                          name: "SID",
	                          index: "SID",
	                          key: true,
	                          hidden: true
	                      }, {
	                          name: 'CTIME',
	                          index: 'CTIME',
	                          width: 90
	                      }, {
	                          name: 'CITYCODE',
	                          index: 'CITYCODE',
	                          width: 90
	                      }, {
	                          name: 'COMMUNITYNAME',
	                          index: 'COMMUNITYNAME',
	                          width: 80
	                      },{
	                          name: 'CBNAME',
	                          index: 'CBNAME',
	                          width: 80
	                      }, {
	                          name: "ROOM",
	                          index: "ROOM",
	                          width: 80
	                      },{
	                          name: "AUNAME",
	                          index: "AUNAME",
	                          width: 80
	                      }, {
	                          name: "APPLYTEL",
	                          index: "APPLYTEL",
	                          width: 90
	                      },{
	                          name: "FIXNAME",
	                          index: "FIXNAME",
	                          width: 80
	                      }, {
	                          name: "FIXTEL",
	                          index: "FIXTEL",
	                          width: 90
	                      }, {
	                          name: "FINISHTIME",
	                          index: "FINISHTIME",
	                          width: 90
	                      }, {
	                          name: "STATUS",
	                          index: "STATUS",
	                          width: 80,
	                          formatter: function (cellvalue, options, rawObject) {
		                          	if(cellvalue=='-1' || !cellvalue){
		                              	return '';
		                              }if (cellvalue == 1){
		                              	return "待回复";
		                              }if (cellvalue == 2 && !rawObject.FIXNAME){
		                            	return "<font style='color: #908e8e;'>待回复</font>";
		                              }else{
		                              	return "<a onclick='replyDetail("+rawObject.SID+")'>已回复</a>";
		                              }
		                          }


	                      }, {
	                          name: "STATUS",
	                          index: "STATUS",
	                          width: 80,
	                          formatter: function (cellvalue, options, rawObject) {
	                         	  if (cellvalue == 1){
										return "<font style='color: red;'>等待处理</font>";
	                              }else if (cellvalue == 2 ){
	                              	return "<font style='color: #908e8e;'>住户撤销</font>";
	                              }else if (cellvalue == 3 ){
	                              	return "<font style='color: red;'>未接单</font>";
	                              }else if (cellvalue == 4 ){
	                              	return "<font style='color: black;'>完成维修</font>";
	                              }else if (cellvalue == 5 ){
	                              	return "<font style='color: black;'>已接单</font>";
	                              }else{
	                            	  return '';
		                          }
	                          }
	                      }],
	                      sortname: 't.sid',
	                      sortorder:'desc',
	                      rownumbers: true,
	                      jsonReader: {
	                          root: 'rows',
	                          page: "page",
	                          total: 'total',
	                          records: "records",
	                          repeatitems: false
	                      },
	                      pager: "#jqGrid_paper",
	                      viewrecords: true,
	                      multiselect: true,
	                      hidegrid: false,
	                      loadComplete: function(){
	                    		var re_records = Number($("#jqGrid").getGridParam('records'));
	                    		var page = Number($("#jqGrid").getGridParam('page'));
	                    		var rows=Number($("#jqGrid").getGridParam('rowNum'));
	                    		var num = re_records-(page-1)*rows;
	                    		if(num < rows)
	                    		{
	                    			for(var i=num;i<rows;i++){
	                    				$("#jqGrid").jqGrid("addRowData",(i+1),
	                            				{ "SID":"","STATUS":"-1"}
	                    				,"");
	                    			}
	                    			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
	                    		}
	                    	}
	                  });
                }else{//社区客户
                	$("#jqGrid").jqGrid({
	                      url: "${pageContext.request.contextPath}/admin/fix_page.action",
	                      mtype: 'POST',
	                      datatype: "json",
	                      height: 362,
	                      autowidth: true,
	                      shrinkToFit: true,
	                      rowNum: 10,
	                      rowList: [10, 20, 30],
	                      colNames: ['序号','申请时间', '楼栋单元','房间号', '住户姓名',
	       	                      '住户手机','维修人员姓名','维修人员手机','完成时间','回复住户','维修状态','操作'],
	                      colModel: [{
	                          name: "SID",
	                          index: "SID",
	                          key: true,
	                          hidden: true
	                      }, {
	                          name: 'CTIME',
	                          index: 'CTIME',
	                          width: 90
	                      },{
	                          name: 'CBNAME',
	                          index: 'CBNAME',
	                          width: 80
	                      }, {
	                          name: "ROOM",
	                          index: "ROOM",
	                          width: 80
	                      },{
	                          name: "AUNAME",
	                          index: "AUNAME",
	                          width: 80
	                      }, {
	                          name: "APPLYTEL",
	                          index: "APPLYTEL",
	                          width: 90
	                      },
// 	                      {
// 	                          name: "TYPE",
// 	                          index: "TYPE",
// 	                          width: 80,
// 	                          formatter: function (cellvalue, options, rawObject) {
// 		                          	if(cellvalue=='-1' || !cellvalue){
// 		                              	return '';
// 		                              }if (cellvalue == 1){
// 		                              	return "<a onclick='applyDetail("+rawObject.SID+")'>水电维修</a>";
// 		                              }else{
// 		                              	return '';
// 		                              }
// 		                          }
// 	                      },
	                      {
	                          name: "FIXNAME",
	                          index: "FIXNAME",
	                          width: 80
	                      }, {
	                          name: "FIXTEL",
	                          index: "FIXTEL",
	                          width: 90
	                      }, {
	                          name: "FINISHTIME",
	                          index: "FINISHTIME",
	                          width: 90
	                      }, {
	                          name: "STATUS",
	                          index: "STATUS",
	                          width: 80,
	                          formatter: function (cellvalue, options, rawObject) {
		                          	if(cellvalue=='-1' || !cellvalue){
		                              	return '';
		                              }else if (cellvalue == 1){
										if(ifreply){
											return "<a onclick='reply("+rawObject.SID+")' style='color: red;'>待回复</a>";
										}else{
											return "待回复";
										}

		                              }else if (cellvalue == 2 && !rawObject.FIXNAME){
		                              	return "<font style='color: #908e8e;'>待回复</font>";
		                              }else{
		                              	return "<a onclick='replyDetail("+rawObject.SID+")'>已回复</a>";
		                              }
		                          }


	                      }, {
	                          name: "STATUS",
	                          index: "STATUS",
	                          width: 80,
	                          formatter: function (cellvalue, options, rawObject) {
	                         	  if (cellvalue == 1){
										return "<font style='color: red;'>等待处理</font>";
	                              }else if (cellvalue == 2 ){
	                              	return "<font style='color: #908e8e;'>住户撤销</font>";
	                              }else if (cellvalue == 3 ){
	                              	return "<font style='color: red;'>未接单</font>";
	                              }else if (cellvalue == 4 ){
	                              	return "<font style='color: black;'>完成维修</font>";
	                              }else if (cellvalue == 5 ){
	                              	return "<font style='color: black;'>已接单</font>";
	                              }else{
	                            	  return '';
		                          }
		                      }

	                      },{
                              name: 'STATUS',
                              index: 'STATUS',
                              width: 80,
                              formatter: function (cellvalue, options, rawObject) {
                            	  if(cellvalue=='-1' || !cellvalue){
		                              	return '';
		                          }else{
		                               	return '<input type="button" style="padding: 2px 10px" class="btn btn-success" value="查看 " onclick="applyDetail('+rawObject.SID+')"/>';
			                      }

                           	}
                          }],
	                      sortname: 't.sid',
	                      sortorder:'desc',
	                      rownumbers: true,
	                      jsonReader: {
	                          root: 'rows',
	                          page: "page",
	                          total: 'total',
	                          records: "records",
	                          repeatitems: false
	                      },
	                      pager: "#jqGrid_paper",
	                      viewrecords: true,
	                      multiselect: true,
	                      hidegrid: false,
	                      loadComplete: function(){
	                    		var re_records = Number($("#jqGrid").getGridParam('records'));
	                    		var page = Number($("#jqGrid").getGridParam('page'));
	                    		var rows=Number($("#jqGrid").getGridParam('rowNum'));
	                    		var num = re_records-(page-1)*rows;
	                    		if(num < rows)
	                    		{
	                    			for(var i=num;i<rows;i++){
	                    				$("#jqGrid").jqGrid("addRowData",(i-100),
	                            				{ "SID":"","TYPE":"-1","STATUS":"-1"}
	                    				,"");
	                    			}
	                    			$(".ui-paging-info").html(re_records-num+1 +" - "+re_records+"　共 "+re_records+" 条");
	                    		}
	                    	}
	                  });
                }
                if('${userRole}' == '1' || '${userRole}' == '2' || '${userRole}' == '21'){
	                $.post("${pageContext.request.contextPath}/admin/tagent_list.action", function (data) {
			            $("#agtCode").empty();
			            $("#agtCode").append("<option value=''>请选择公司</option>");
			            for (var i = 0; i < data.length; i++) {
			                $("#agtCode").append("<option value='" + data[i].agtCode + "'>" + data[i].agtName + "</option>");
			            }
			            $("#agtCode").select2({
			                "placeholder": "请选择公司",
			                "width": "100%"
			            })
			            $("#communityId").append("<option value=''>请选择社区</option>");
			            $("#agtCode").change(function () {
			            	var data = $(this).val();
			            	$.post("${pageContext.request.contextPath}/admin/tcommunity_list.action", {"agtCode": data},function (data) {
					            $("#communityId").empty();
					            $("#communityId").append("<option value=''>请选择社区</option>");
					            for (var i = 0; i < data.length; i++) {
					                $("#communityId").append("<option value='" + data[i].sid + "'>" + data[i].communityName + "</option>");
					            }

					            $("#communityId").select2({
					                "placeholder": "请选择社区",
					                "width": "100%"
					            })

					        }, "json");
			            })
			        }, "json");
                }else if('${userRole}' == '3' || '${userRole}' == '4' ){
                	$.post("${pageContext.request.contextPath}/admin/tcommunity_list.action",
                        function (data) {
			            $("#communityId").empty();
			            $("#communityId").append("<option value=''>请选择社区</option>");
			            for (var i = 0; i < data.length; i++) {
			                $("#communityId").append("<option value='" + data[i].sid + "'>" + data[i].communityName + "</option>");
			            }
			            $("#communityId").select2({
			                "placeholder": "请选择社区",
			                "width": "100%"
			            })

			        }, "json");
                }
                <!--查询-->
                jQuery("#query").click(query);
                jQuery("#resetForm").click(resetForm);
            });
    $("#communityId").select2({
        "placeholder": "请选择社区",
        "minimumResultsForSearch":-1
    })
     $("#replytype").select2({
        "placeholder": "请选择回复状态",
        "minimumResultsForSearch":-1
    })
     $("#status").select2({
        "placeholder": "请选择维修状态",
        "minimumResultsForSearch":-1
    })
    <!--刷新jqGrid表格数据-->
    function refreshGrid() {
        $("#jqGrid").trigger("reloadGrid");
    }
    function resetForm() {
        location.reload();
        return false;
    }
    function reply(sid){
    	layer.open({
            type: 2,
            title: '<strong>选择维修人员</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['400px', '280px'],
            content: '${pageContext.request.contextPath}/admin/fix_replyView.action?sid='
            + sid,
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var options = {
                    success: function (data) {
                        data = JSON.parse(data);
                        if (data.code == 1) {
                            layer.alert(data.msg, function () {
                                layer.closeAll();
                                refreshGrid();
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                    }
                };
               	 	$("#layui-layer-iframe" + index).contents().find("#form").ajaxForm(options);
              		$("#layui-layer-iframe" + index).contents().find("#form").submit();
            }
        });
    }
    function replyDetail(sid){
    	layer.open({
            type: 2,
            title: '<strong>回复</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['400px', '280px'],
            content: '${pageContext.request.contextPath}/admin/fix_replyDetailView.action?sid='
            + sid,
            btn: ['确定'],
            yes: function (index, layero) {
                  layer.closeAll();
             }
        });
    }
    function applyDetail(sid){
    	layer.open({
            type: 2,
            title: '<strong>维修详情</strong>',
            shadeClose: true, //点击遮罩关闭层
            area: ['800px', '580px'],
            content: '${pageContext.request.contextPath}/admin/fix_applyDetailView.action?sid='
            + sid,
            btn: ['确定'],
            yes: function (index, layero) {
                  layer.closeAll();
             }
        });
    }
    function query() {
        var agtCode = $("#agtCode").val();
        var communityId = $("#communityId").val();
        var areaCode;
        if('${userRole}' != 5 && '${userRole}' != 6){
	        var selects=document.getElementsByName('location');
	        areaCode = selects[0].value;
		}
        var userName = $("#userName").val();
        var userTel = $("#userTel").val();
        var replytype = $("#replytype").val();
        var status = $("#status").val();
        $("#jqGrid").jqGrid('setGridParam', {
            url: "${pageContext.request.contextPath}/admin/fix_page.action",
            postData: {
                'agtCode': agtCode,
                'communityId': communityId,
                'areaCode': areaCode,
                'userName': userName,
                'userTel': userTel,
                'replytype': replytype,
                'status': status
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入*/
        return false;
    }

//     function haveReplyView(){
//         layer.open({
//             type: 2,
//             title: ['回复', 'font-weight:bold'],
//             shadeClose: true, //点击遮罩关闭层
//             area: ['800px', '430px'],
//             scrollbar: false,
//             content: '${pageContext.request.contextPath}/admin/fix_replyView.action',
//             btn: ['确定'],
//             yes: function (index, layero) {
//             	layer.close(index);
//             }
//         });
//     }

window.onload=function(){

	function BrowserType(){
		//获取浏览器的userAgent代理号；
		var userAgent=navigator.userAgent;

		//判断是否是Opera浏览器
		var isOpera=userAgent.indexOf("Opera")>-1;
		//判断是否是IE浏览器
		var isIE=userAgent.indexOf("compatible")>-1 && userAgent.indexOf("MSIE")>-1 && !isOpera;
		//判断是否是IE7浏览器
		if(isIE){
			var relIE=new RegExp("MSIE(\\d+\\.\\d+);");

			relIE.test(userAgent);
			var arr=userAgent.split(";")
			var flEVersion=arr[1].indexOf("7");
			if(flEVersion>-1){
				var $td=$(".jqgrid-rownum")[0];
				$td.style.width="0";
				$tr=$("thead tr th");
				$td=$("tbody tr td");
				var len=$tr.length;
				for(var i=0;i<len;i++){
					$tr[i].style.width=10+"px";
					$td[i].style.width=10+"px";
				};
			}
		}
	};
	BrowserType();
};
</script>
</body>
</html>
